package com.peans.web;

import java.util.concurrent.TimeUnit;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.springframework.boot.Banner;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.builder.SpringApplicationBuilder;
import org.springframework.boot.context.embedded.EmbeddedServletContainerFactory;
import org.springframework.boot.context.embedded.undertow.UndertowEmbeddedServletContainerFactory;
import org.springframework.boot.web.support.SpringBootServletInitializer;
import org.springframework.context.annotation.Bean;

@SpringBootApplication
public class WebConfig extends SpringBootServletInitializer{
	
	private static final Log logger = LogFactory.getLog(WebConfig.class);
	
	@Bean
	public EmbeddedServletContainerFactory servletContainer() {
		logger.debug("######################");
		UndertowEmbeddedServletContainerFactory factory = new UndertowEmbeddedServletContainerFactory();
		//factory.setPort(9000);
		factory.setSessionTimeout(10, TimeUnit.MINUTES);
		//factory.addErrorPages(new ErrorPage(HttpStatus.NOT_FOUND, "/notfound.html"));
		return factory;
	}
	
	//@Autowired
	//private DataSourceProperties properties;
	
	/**
	@Bean
	@ConfigurationProperties(prefix = DataSourceProperties.PREFIX)
	public DataSource druidDataSource(){
		DruidDataSource dataSource = new DruidDataSource();
		dataSource.setDriverClassName(properties.getDriverClassName());
		dataSource.setUrl(properties.getUrl());
		dataSource.setUsername(properties.getUsername());
		dataSource.setPassword(properties.getPassword());
		dataSource.setMinIdle(1);
		try {
			dataSource.setFilters("stat");
		} catch (SQLException e) {
			e.printStackTrace();
		}
		return dataSource;
	}
	**/
	
	
	@Override
	protected SpringApplicationBuilder configure(SpringApplicationBuilder application) {
		return application.sources(WebConfig.class);
	}

	public static void main(String[] args) throws Exception {
		SpringApplication app = new SpringApplication(WebConfig.class);
		app.setBannerMode(Banner.Mode.CONSOLE);
		app.run(args);
		//SpringApplication.run(WebConfig.class, args);
	}

}
